package com.batchengine.worker;

import static com.batchengine.Definitions.ContextParams.TASK_INSTANCE;
import com.batchengine.task.Task;
import com.batchengine.task.TaskContext;
import com.batchengine.util.LoggingFactory;
import static com.batchengine.worker.WorkerType.EXECUTER;
import com.batchengine.Definitions;
import org.apache.log4j.Logger;

/**
 * Created by sunil.incubator@yahoo.com.
 * User: sunil.kalva
 * Date: Jul 19, 2009
 */
public class Executor extends Worker {

    private static final Logger logger = LoggingFactory.createLogger();

    private Task task;

    public Executor(String name, long taskId) {
        super(name, taskId);
    }

    protected Executor(String name, long taskId, ThreadGroup workGroup) {
        super(name, taskId, workGroup);
    }

    protected Executor(String name, long taskId, ThreadGroup workGroup, int workerPriority) {
        super(name, taskId, workGroup, workerPriority);
    }

    @Override
    public WorkerType getType() {
        return EXECUTER;
    }

    @Override
    protected void doWork(TaskContext context) {

//        logger.debug("executing Executor#dowork ==> " + context.getContextParam(Definitions.ContextParams.TASK_ID));
        Task task = (Task) context.getContextParam(TASK_INSTANCE);
        context.addcontextParam(Definitions.ContextParams.OWNER, this);
        task.execute(context);
    }
}
